
function api(url, request){
    return new Promise((resolve, reject)=>{
        $.ajax({
            url,
            data:request,
            type:'POST',
            timeout : 30000,
            success:(data)=>{
                if(data.errorCode == -100){
                    alertTips.toast("登录已失效")
                    location.href = "/"
                    return
                }
                resolve(data);
            },
            error:(data)=>{
                reject(data);
            },
            complete : function(XMLHttpRequest,status){ //请求完成后最终执行参数
        　　　　if(status=='timeout'){//超时,status还有success,error等值的情况
               
        　　　　}
        　　}
        });
    });
}

api.upload = function(url,dataform){
    return new Promise((resolve, reject) =>{
        $.ajax({
            url,
            data:dataform,
            type:'POST',
            contentType: false,  
            processData: false,  
            success:(data) =>{
                if(data.errorCode == -100){
                    alertTips.toast("登录已失效")
                    location.href = "/"
                    return
                }
              resolve(data)
            }
        })
    });
}
api.sleep = function (time){
    return new Promise((resolve,reject) => {
        let times = setTimeout(() => {
            clearTimeout(times)
            resolve();
        },time * 1000)
    })
    
}
module.exports= api